package registe.untill.baseUntill;

import org.json.JSONObject;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * Created by zhoumeineng on 2018/1/25.
 *  返回字段处理的工具
 */
public  class MessageUntill {

    /**
     * 封装 返回给前端的消息体
     * */
    public static JSONObject messageBody(Map map,String respCode,String respDesc){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("respCode",respCode);
        jsonObject.put("respDesc",respDesc);
        if (map!=null){
            JSONObject object1 = new JSONObject(map);
            jsonObject.put("attach",object1);
        }
        return jsonObject;
    }


    /**
     *
     * 输出
     * */
    public static void ResboneOutPut(HttpServletResponse rsp,JSONObject jsonObject){
        PrintWriter writer = null;
        try {
            writer = rsp.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.print(jsonObject.toString());
        writer.flush();
    }
}
